 /**
 * 逻辑、功能相关描述:
 *
 * @author yandawei 编写日期：2008-9-16
 */
package com.ce.pms.common.model;

import java.io.Serializable;

import javax.persistence.*;

import com.sitechasia.webx.core.model.IDomainObject;

/**
 * 实体名称:用户权限映射表 关联数据表:SEC_USER_R_RIGTHS
 *
 */
@Entity
@Table(name = "SEC_USER_R_RIGTHS")
public class SecUserRelationRight implements IDomainObject {

	@Embeddable
	public static class Id implements Serializable
	{
		@Column(name="USER_ID")
		private Long userId;

		@Column(name="RIGHT_ID")
		private Long rightId;

		public Id(){}

		public Id(Long userId,Long rightId)
		{
			this.userId = userId;
			this.rightId = rightId;
		}
		public boolean equals(Object o){
			if(o!= null && o instanceof Id){
				Id that = (Id)o;
				return this.userId.equals(that.userId) &&
						this.rightId.equals(that.rightId);
			}else{
				return false;
			}
		}

		public int hashCode(){
			return userId.hashCode()+rightId.hashCode();
		}
	}

	@EmbeddedId
	private Id id = new Id();
	/**
	 * 用户
	 */
	@ManyToOne(cascade = {}, fetch = FetchType.EAGER)
	@org.hibernate.annotations.Cascade(value={
			org.hibernate.annotations.CascadeType.SAVE_UPDATE
	})
	@JoinColumn(name="USER_ID",nullable=false,updatable=false,insertable = false)
	private SecUser secUser;

	/**
	 * 权限
	 */
	@ManyToOne(cascade = {}, fetch = FetchType.EAGER)
	@org.hibernate.annotations.Cascade(value={
			org.hibernate.annotations.CascadeType.SAVE_UPDATE
	})
	@JoinColumn(name="RIGHT_ID",nullable=false,updatable=false,insertable = false)
	private SecRight secRight;

	/***
	 * 资源ID
	 */
	@Column(name ="RESOUCE_ID" , nullable = false)
	private Long resourceId;

	/**
	 * 权限类型编号
	 */
	@Column(name ="TYPE_CODE" , length = 3 , nullable =false)
	private String typeCode;

	public SecUserRelationRight(){}

	public SecUserRelationRight(
			SecUser secUser,
			SecRight secRight,
			Long resourceId,
			String typeCode){
		this.secUser =secUser;
		this.secRight = secRight;
		this.resourceId = resourceId;
		this.typeCode = typeCode;

		this.id.userId = secUser.getUserId();
		this.id.rightId = secRight.getRightId();
//		secUser.getSecUserRelationRights().add(this);
//		secRight.getSecUserRelationRights().add(this);
	}

	public Long getResourceId() {
		return resourceId;
	}

	public void setResourceId(Long resourceId) {
		this.resourceId = resourceId;
	}

	public SecRight getSecRight() {
		return secRight;
	}

	public void setSecRight(SecRight secRight) {
		this.secRight = secRight;
	}

	public SecUser getSecUser() {
		return secUser;
	}

	public void setSecUser(SecUser secUser) {
		this.secUser = secUser;
	}

	public String getTypeCode() {
		return typeCode;
	}

	public void setTypeCode(String typeCode) {
		this.typeCode = typeCode;
	}


}
